<?php

namespace App\Repositories;

use App\Interfaces\IRepository;
use App\Models\Tag;

abstract class BaseRepository implements IRepository
{

    /**
     * The Model instance.
     *
     * @var Illuminate\Database\Eloquent\Model
     */
    protected $model;

    /**
     * Get Model by id.
     *
     * @param  int $id
     * @return App\Model
     */
    public function getById($id)
    {
        return $this->model->findOrFail($id);
    }



    public function destroy($id = 0, $extra = '')
    {
        $first_tag = $this->getById($id);
        $tags = Tag::where('pid',$first_tag->id)->get();
        if($tags){
            foreach ($tags as $tag) {
                $this->destroy($tag->id);
            }
        }
        Tag::destroy($first_tag->id);
    }


}
